package server.content.randoms;

import java.util.LinkedList;
import java.util.List;

import core.util.Misc;
import server.Server;
import server.event.CycleEvent;
import server.event.CycleEventContainer;
import server.event.CycleEventHandler;
import server.game.npcs.NPC;
import server.game.players.Client;

public class TreeSpirit implements RandomEvent {

	private final Client c;
	private final List<NPC> removeList = new LinkedList<NPC>();

	public TreeSpirit(final Client c) {
		this.c = c;
	}

	@Override
	public void initRandom() {
		final int outOf = Misc.random(15000);
		final int chance = Misc.random(25);
		if (outOf <= chance) {
			final int npcId = getAppropriateNpc();
			final int npcDmg = getMaxHit(npcId);
			Server.npcHandler.spawnNpc(c, npcId, c.absX, c.absY, 0, 0, 120,
					npcDmg, 70, 70, true, false);
		}
	}

	public int getMaxHit(final int npcId) {
		switch (npcId) {
		case 438:
			return 4;
		case 439:
			return 8;
		case 440:
			return 12;
		case 441:
			return 16;
		case 442:
			return 21;
		}
		return -1;
	}

	public int getAppropriateNpc() {
		if (c.combatLevel > 2 && c.combatLevel < 26) {
			return 438;
		} else if (c.combatLevel > 25 && c.combatLevel < 51) {
			return 439;
		} else if (c.combatLevel > 50 && c.combatLevel < 76) {
			return 440;
		} else if (c.combatLevel > 75 && c.combatLevel < 101) {
			return 441;
		} else if (c.combatLevel > 100 && c.combatLevel < 127) {
			return 442;
		}
		return -1;
	}

	public Client getClient() {
		return c;
	}

}
